/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package east2west.dao;

import east2west.dto.FunctionDTO;
import east2west.dto.RoleFunctionDTO;
import east2west.interfaces.RoleFunctionInterface;
import east2west.util.DatabaseUtil;
import java.sql.Statement;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;

/**
 *
 * @author anhtuan
 */
public class RoleFunctionDAO implements RoleFunctionInterface {

    Connection con = null;
    CallableStatement call = null;
    PreparedStatement pst = null;
    ResultSet rs = null;
    RoleFunctionDTO rolefunctionDTO = null;

    public ArrayList<RoleFunctionDTO> readByAll() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public boolean create(RoleFunctionDTO dto) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public boolean update(RoleFunctionDTO dto, RoleFunctionDTO dtoNew) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public boolean delete(RoleFunctionDTO dto) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public ArrayList<RoleFunctionDTO> readByRoleId(int RoleId) {
        ArrayList<RoleFunctionDTO> list = null;
        try {
            con = DatabaseUtil.getConnection();
            pst = con.prepareCall("select * from V_RoleFunction where RoleId = ?");
            pst.setInt(1, RoleId);
            rs = pst.executeQuery();
            list = new ArrayList<RoleFunctionDTO>();
            while (rs.next()) {
                rolefunctionDTO = new RoleFunctionDTO();
                rolefunctionDTO.setFunctionId(1);
                FunctionDTO FuncDTO = new FunctionDTO();
                FuncDTO.setFunctionName(rs.getString(2));
                rolefunctionDTO.setFuncDTO(FuncDTO);
                list.add(rolefunctionDTO);
            }
            rs.close();
            pst.close();
            return list;
        } catch (Exception ex) {
            return null;
        } finally {
            DatabaseUtil.closeConnection(con);
        }
    }
}
